home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / emacs_src_18_58.lha / emacs-18.58 / lisp / term / sun.el < prev    next >
Lisp/Scheme  |  1992-02-21  |  11KB  |  294 lines

  1. ;; keybinding for standard default sunterm keys
  2. ;; Copyright (C) 1987 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 1, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. ;;  Jeff Peck, Sun Microsystems Inc  <peck@sun.com>
  21.  
  22. (defun ignore-key ()
  23.   "interactive version of ignore"
  24.   (interactive)
  25.   (ignore))
  26.  
  27. (defun unbound-key ()
  28.   "filler for compound keymaps"
  29.   (interactive)
  30.   (error "unbound-key"))
  31.  
  32. (defun scroll-down-in-place (n)
  33.   (interactive "p")
  34.   (previous-line n)
  35.   (scroll-down n))
  36.  
  37. (defun scroll-up-in-place (n)
  38.   (interactive "p")
  39.   (next-line n)
  40.   (scroll-up n))
  41.  
  42. (defun kill-region-and-unmark (beg end)
  43.   "Like kill-region, but pops the mark [which equals point, anyway.]"
  44.   (interactive "r")
  45.   (kill-region beg end)
  46.   (setq this-command 'kill-region-and-unmark)
  47.   (set-mark-command t))
  48.  
  49. (defun prev-complex-command ()
  50.   "Select Previous-complex-command"
  51.   (interactive)
  52.   (if (zerop (minibuffer-depth))
  53.       (repeat-complex-command 1)
  54.     (previous-complex-command 1)))
  55.  
  56. (defun rerun-prev-command ()
  57.   "Repeat Previous-complex-command."
  58.   (interactive)
  59.   (eval (nth 0 command-history)))
  60.  
  61. (defvar grep-arg nil "Default arg for RE-search")
  62.  
  63. (defun prev-search-command-arg ()
  64.   ;; if previous minibuf command specified a search string, return it.
  65.   ;; this way, a call to M-x re-search-forward can pass its arg.
  66.   (let* ((command (car command-history))
  67.      (command-name (symbol-name (car command)))
  68.      (search-arg (car (cdr command)))
  69.      (search-command 
  70.       (and command-name (string-match "search" command-name))))
  71.     (and search-command (stringp search-arg) search-arg)))
  72.  
  73. (defun grep-arg (&optional prompt)
  74.   "helper function used by research-{backward,forward}"
  75.   (if (memq last-command '(research-forward research-backward)) grep-arg
  76.     (let ((this-command this-command)    ; save this binding from read-string
  77.       (default (or (prev-search-command-arg)
  78.                search-last-regexp
  79.                grep-arg)))
  80.       (read-string (or prompt "Regexp arg: ") default))))
  81.  
  82. (defun research-forward ()
  83.   "Repeat regexp search forward, using previous search arg if available."
  84.   (interactive)                ;
  85.   (if (re-search-forward (grep-arg "Regexp search: "))
  86.       (setq search-last-regexp grep-arg)))
  87.  
  88. (defun research-backward ()
  89.   "Repeat regexp search backward, using previous search arg if available."
  90.   (interactive)                ;
  91.   (if (re-search-backward (grep-arg "Regexp search backward: "))
  92.       (setq search-last-regexp grep-arg)))
  93.  
  94. ;;;
  95. ;;; handle sun's extra function keys
  96. ;;; this version for those who run with standard .ttyswrc and no emacstool
  97. ;;;
  98. ;;; sunview picks up expose and open on the way UP, 
  99. ;;; so we ignore them on the way down
  100. ;;;
  101.  
  102. (defvar sun-esc-bracket nil
  103.   "*If non-nil, rebind ESC [ as prefix for Sun function keys.")
  104.  
  105. (defvar sun-raw-map (make-sparse-keymap) "*Keymap for ESC-[ encoded keyboard")
  106.  
  107. (define-key sun-raw-map "208z" 'unbound-key)        ; R3
  108. (define-key sun-raw-map "209z" 'unbound-key)        ; R3
  109. (define-key sun-raw-map "210z" 'backward-page)        ; R3
  110. (define-key sun-raw-map "213z" 'forward-page)        ; R6
  111. (define-key sun-raw-map "214z" 'beginning-of-buffer)    ; R7
  112. (define-key sun-raw-map "216z" 'scroll-down)        ; R9
  113. (define-key sun-raw-map "215z" 'previous-line)        ; R8  (up-arrow)
  114. (define-key sun-raw-map "217z" 'backward-char)        ; R10 (rt-arrow)
  115. (define-key sun-raw-map "219z" 'forward-char)        ; R12 (dn-arrow)
  116. (define-key sun-raw-map "221z" 'next-line)        ; R14 (lf-arrow)
  117. (define-key sun-raw-map "218z" 'recenter)               ; R11
  118. (define-key sun-raw-map "220z" 'end-of-buffer)        ; R13
  119. (define-key sun-raw-map "222z" 'scroll-up)        ; R15
  120. (define-key sun-raw-map "193z" 'redraw-display)        ; Again    L1
  121. (define-key sun-raw-map "194z" 'list-buffers)        ; Props    L2
  122. (define-key sun-raw-map "195z" 'undo)            ; Undo    L3
  123. (define-key sun-raw-map "196z" 'ignore-key)        ; Expose-down    L4
  124. (define-key sun-raw-map "197z" 'sun-select-region)    ; Put    L5
  125. (define-key sun-raw-map "198z" 'ignore-key)        ; Open-down    L6
  126. (define-key sun-raw-map "199z" 'sun-yank-selection)    ; Get    L7
  127. (define-key sun-raw-map "200z" 'exchange-point-and-mark); Find    L8
  128. (define-key sun-raw-map "201z" 'kill-region-and-unmark)    ; Delete    L9
  129. (define-key sun-raw-map "225z" 'toggle-selective-display); T2
  130. (define-key sun-raw-map "226z" 'scroll-down-in-place)    ; T3
  131. (define-key sun-raw-map "227z" 'scroll-up-in-place)    ; T4
  132. (define-key sun-raw-map "228z" 'shell)            ; T5
  133. (define-key sun-raw-map "229z" 'shrink-window)        ; T6
  134. (define-key sun-raw-map "230z" 'enlarge-window)        ; T7
  135.  
  136. (if sun-esc-bracket
  137.     (progn
  138.       (define-key esc-map "[" sun-raw-map)        ; Install sun-raw-map
  139.       (define-key esc-map "[A" 'previous-line )        ; R8
  140.       (define-key esc-map "[B" 'next-line)        ; R14
  141.       (define-key esc-map "[C" 'forward-char)        ; R12
  142.       (define-key esc-map "[D" 'backward-char)        ; R10
  143.       (define-key esc-map "[[" 'backward-paragraph)    ; the original esc-[
  144.       ))
  145.  
  146. ;;; Since .emacs gets loaded before this file, a hook is supplied
  147. ;;; for you to put your own bindings in.
  148.  
  149. (defvar sun-raw-map-hooks nil
  150.   "List of forms to evaluate after setting sun-raw-map.")
  151.  
  152. (let ((hooks sun-raw-map-hooks))
  153.   (while hooks
  154.     (eval (car hooks))
  155.     (setq hooks (cdr hooks))
  156.     ))
  157.  
  158.  
  159. ;;; This section adds defintions for the emacstool users
  160. ;;; emacstool event filter converts function keys to C-x*{c}{lrt}
  161. ;;;
  162. ;;; for example the Open key (L7) would be encoded as "\C-x*gl"
  163. ;;; the control, meta, and shift keys modify the character {lrt}
  164. ;;; note that (unshifted) C-l is ",",  C-r is "2", and C-t is "4"
  165. ;;;
  166. ;;; {c} is [a-j] for LEFT, [a-i] for TOP, [a-o] for RIGHT.
  167. ;;; A higher level insists on encoding {h,j,l,n}{r} (the arrow keys)
  168. ;;; as ANSI escape sequences.  Use the shell command 
  169. ;;; % setkeys noarrows
  170. ;;; if you want these to come through for emacstool.
  171. ;;;
  172. ;;; If you are not using EmacsTool, 
  173. ;;; you can also use this by creating a .ttyswrc file to do the conversion.
  174. ;;; but it won't include the CONTROL, META, or SHIFT keys!
  175. ;;;
  176.  
  177. ;;; Note:  al (STOP), el (EXPOSE) and gl (OPEN) are trapped by EmacsTool, 
  178. ;;; so they never make it here.
  179.  
  180. (defvar meta-flag t)
  181.  
  182. (defvar suntool-map (make-sparse-keymap)
  183.   "*Keymap for Emacstool bindings.")
  184.  
  185. (define-key suntool-map "ar" 'unbound-key)        ; R1
  186. (define-key suntool-map "br" 'unbound-key)        ; R2
  187. (define-key suntool-map "hr" 'previous-line)        ; R8  (up-arrow)
  188. (define-key suntool-map "jr" 'backward-char)        ; R10 (rt-arrow)
  189. (define-key suntool-map "lr" 'forward-char)        ; R12 (dn-arrow)
  190. (define-key suntool-map "nr" 'next-line)        ; R14 (lf-arrow)
  191. (define-key suntool-map "gr" 'beginning-of-buffer)    ; r7
  192. (define-key suntool-map "iR" 'backward-page)        ; R9
  193. (define-key suntool-map "ir" 'scroll-down)        ; r9
  194. (define-key suntool-map "kr" 'recenter)            ; r11
  195. (define-key suntool-map "mr" 'end-of-buffer)        ; r13
  196. (define-key suntool-map "oR" 'forward-page)        ; R15
  197. (define-key suntool-map "or" 'scroll-up)        ; r15
  198. (define-key suntool-map "b\M-L" 'rerun-prev-command)    ; M-AGAIN
  199. (define-key suntool-map "b\M-l" 'prev-complex-command)    ; M-Again
  200. (define-key suntool-map "bl" 'redraw-display)        ; Again    L1
  201. (define-key suntool-map "cl" 'list-buffers)        ; Props    L2
  202. (define-key suntool-map "dl" 'undo)            ; Undo    L3
  203. (define-key suntool-map "el" 'ignore-key)        ; Expose-Top    L4
  204. (define-key suntool-map "fl" 'sun-select-region)    ; Put    L5
  205. (define-key suntool-map "f," 'copy-region-as-kill)    ; C-Put    L5
  206. (define-key suntool-map "gl" 'ignore-key)        ; Open-Open    L6
  207. (define-key suntool-map "hl" 'sun-yank-selection)    ; Get    L7
  208. (define-key suntool-map "h," 'yank)            ; C-Get
  209. ;; interactive regexp search                ; Find    L8
  210. (define-key suntool-map "iL" 're-isearch-forward)    ; FIND (shift-Find)
  211. (define-key suntool-map "i\M-L" 're-isearch-backward)    ; M-FIND (M-shift-Find)
  212. ;; non-interactive versions: 
  213. ;; search again, using previous search arg as regexp.
  214. (define-key suntool-map "il" 'research-forward)        ; Find
  215. (define-key suntool-map "i\M-l" 'research-backward)    ; M-Find
  216. ;; supply new arg
  217. (define-key suntool-map "i," 're-search-forward)    ; C-Find
  218. (define-key suntool-map "i\M-," 're-search-backward)    ; C-M-Find
  219.  
  220. (define-key suntool-map "jL" 'yank)            ; DELETE  L9      
  221. (define-key suntool-map "jl" 'kill-region-and-unmark)    ; Delete
  222. (define-key suntool-map "j\M-l" 'exchange-point-and-mark); M-Delete
  223. (define-key suntool-map "j," 
  224.   '(lambda () (interactive) (pop-mark 1)))        ; C-Delete
  225.  
  226. (define-key suntool-map "bt" 'toggle-selective-display)     ; t2
  227. (define-key suntool-map "cT" '(lambda(n) (interactive "p") (scroll-down n)))
  228. (define-key suntool-map "dT" '(lambda(n) (interactive "p") (scroll-up n)))
  229. (define-key suntool-map "ct" 'scroll-down-in-place)        ; t3
  230. (define-key suntool-map "dt" 'scroll-up-in-place)        ; t4
  231. (define-key suntool-map "et" 'shell)                ; t5
  232. (define-key suntool-map "fT" 'shrink-window-horizontally)    ; T6
  233. (define-key suntool-map "gT" 'enlarge-window-horizontally)    ; T7
  234. (define-key suntool-map "ft" 'shrink-window)            ; t6
  235. (define-key suntool-map "gt" 'enlarge-window)            ; t7
  236. (define-key ctl-x-map "*" suntool-map)
  237.  
  238. ;;; Since .emacs gets loaded before this file, a hook is supplied
  239. ;;; for you to put your own bindings in.
  240.  
  241. ;;; Example:
  242. ;(setq suntool-map-hooks '(            ; not your usual hook list
  243. ;  (define-key suntool-map "c\M-l" 'browse)     ; Meta-Props
  244. ;  (define-key suntool-map "dr" 'goto-line)     ; R4
  245. ;  (define-key suntool-map "d2" 'what-line)     ; Control-R4
  246. ;  ))
  247.  
  248. (defvar suntool-map-hooks nil
  249.   "List of forms to evaluate after setting suntool-map.")
  250.  
  251. (let ((hooks suntool-map-hooks))
  252.   (while hooks
  253.     (eval (car hooks))
  254.     (setq hooks (cdr hooks))
  255.     ))
  256.  
  257. ;;;
  258. ;;; If running under emacstool, arrange to call suspend-emacstool
  259. ;;; instead of suspend-emacs.
  260. ;;;
  261. ;;; First mouse blip is a clue that we are in emacstool.
  262. ;;;
  263. ;;; C-x C-@ is the mouse command prefix.
  264.  
  265. (autoload 'sun-mouse-handler "sun-mouse" 
  266.       "Sun Emacstool handler for mouse blips (not loaded)." t)
  267.  
  268. (defun emacstool-init ()
  269.   "Set up Emacstool window, if you know you are in an emacstool."
  270.   ;; Make sure sun-mouse and sun-fns are loaded.
  271.   (require 'sun-fns)
  272.   (define-key ctl-x-map "\C-@" 'sun-mouse-handler)
  273.  
  274.   (if (< (sun-window-init) 0)
  275.       (message "Not a Sun Window")
  276.     (progn
  277.       (substitute-key-definition 'suspend-emacs 'suspend-emacstool global-map)
  278.       (substitute-key-definition 'suspend-emacs 'suspend-emacstool esc-map)
  279.       (substitute-key-definition 'suspend-emacs 'suspend-emacstool ctl-x-map))
  280.       (send-string-to-terminal
  281.        (concat "\033]lEmacstool - GNU Emacs " emacs-version "\033\\"))
  282.     ))
  283.  
  284. (defun sun-mouse-once ()
  285.   "Converts to emacstool and sun-mouse-handler on first mouse hit."
  286.   (interactive)
  287.   (emacstool-init)
  288.   (sun-mouse-handler)            ; Now, execute this mouse blip.
  289.   )
  290. (define-key ctl-x-map "\C-@" 'sun-mouse-once)
  291.  
  292. ;;; If Emacstool is being nice, and informs us of its presence:
  293. (if (getenv "IN_EMACSTOOL") (emacstool-init))
  294.